﻿namespace WebRole1
{
	#region Usings

	using System;
	using System.Web.UI;

	using Helpers;

	using Microsoft.WindowsAzure;
	using Microsoft.WindowsAzure.StorageClient;

	#endregion

	public partial class _Default : Page
	{
		protected void Button1Click(object sender, EventArgs e)
		{
			CloudStorageAccount account = CloudStorageAccount.FromConfigurationSetting("StorageConnectionString");
			CloudQueueClient queueClient = account.CreateCloudQueueClient();
			CloudQueue queue = queueClient.GetQueueReference("myfirstqueue");

			if(!queue.Exists ())
			{
				Label1.Text = "The queue doesn't exist.";
				return;
			}

			MessageObject mo = new MessageObject
			{
				ID = new Random(500).Next(),
				Description = "Description" + Guid.NewGuid(),
				Title = "Title" + Guid.NewGuid()
			};

			CloudQueueMessage message = new MyCloudQueueMessage(mo);
			queue.AddMessage(message);

			Label1.Text = "Message Sent";
		}
	}
}